//
//  LYQIntegralHeaderView.m
//  ZCProject
//
//  Created by Zheng on 16/12/6.
//  Copyright © 2016年 Zheng. All rights reserved.
//

#import "LYQIntegralHeaderView.h"

#import "LYQIntegralDescriptionViewController.h"


@implementation LYQIntegralHeaderView

- (instancetype)init {
    
    self = [super init];
    
    if (self == nil) {
        return nil;
    }
    
    [self addSubview:self.decorationView];
    [self addSubview:self.titleLbl];
    [self addSubview:self.instructionsBtn];
    
    [self layoutSubviewsInView];
    
    return self;
}

#pragma mark - headerview layout subviews
- (void)layoutSubviewsInView {
    
    [_decorationView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(kWScale(4));
        make.height.mas_equalTo(kWScale(14));
        make.left.centerY.equalTo(self);
    }];
    
    [_titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_decorationView.mas_right).offset(kWScale(10));
        make.top.bottom.equalTo(self);
    }];
    
    [_instructionsBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-kWScale(15));
        make.centerY.equalTo(self);
    }];
}

#pragma mark - headerview load subviews
- (UIView *)decorationView {
    if (!_decorationView) {
        _decorationView = [[UIView alloc] init];
        _decorationView.backgroundColor = kLYQBlue;
    }
    return _decorationView;
}

- (UILabel *)titleLbl {
    if (!_titleLbl) {
        _titleLbl = [[UILabel alloc] init];
        _titleLbl.font = kWFont(16);
        _titleLbl.textColor = kLYQBlack;
    }
    return _titleLbl;
}

- (UIButton *)instructionsBtn {
    if (_instructionsBtn) {
        return _instructionsBtn;
    }
    
    _instructionsBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_instructionsBtn setTitle:@"积分说明" forState:UIControlStateNormal];
    [_instructionsBtn setTitleColor:kHexadecimal(@"666666") forState:UIControlStateNormal];
    _instructionsBtn.titleLabel.font = kWFont(15);
    [_instructionsBtn addTarget:self action:@selector(instructionsBtnAction) forControlEvents:UIControlEventTouchUpInside];
    
    return _instructionsBtn;
}

#pragma mark - 跳转积分说明页面
- (void)instructionsBtnAction {
    LYQIntegralDescriptionViewController *idVC = [[LYQIntegralDescriptionViewController alloc] init];
    [self.viewController.navigationController pushViewController:idVC animated:YES];
}



@end
